/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jsf.view;

import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.primefaces.PrimeFaces;

/**
 *
 * @author gang
 */
public abstract class PageBean implements Serializable {

    public void info(String summary) {
        info("信息", summary);
    }

    public void info(String summary, String detail) {
        msg(FacesMessage.SEVERITY_INFO, summary, detail);
    }

    public void info(String clientId, String summary, String detail) {
        msg(clientId, FacesMessage.SEVERITY_INFO, summary, detail);
    }

    public void warn(String summary) {
        warn("警告", summary);
    }

    public void warn(String summary, String detail) {
        msg(FacesMessage.SEVERITY_WARN, summary, detail);
    }

    public void warn(String clientId, String summary, String detail) {
        msg(clientId, FacesMessage.SEVERITY_WARN, summary, detail);
    }

    public void error(String summary) {
        error("错误", summary);
    }

    public void error(String summary, String detail) {
        msg(FacesMessage.SEVERITY_ERROR, summary, detail);
    }

    public void error(String clientId, String summary, String detail) {
        msg(clientId, FacesMessage.SEVERITY_ERROR, summary, detail);
    }

    private void msg(FacesMessage.Severity severity, String summary, String detail) {
        msg(null, severity, summary, detail);
    }

    private void msg(String clientId, FacesMessage.Severity severity, String summary, String detail) {
        FacesMessage message = new FacesMessage(severity, summary, detail);
        FacesContext.getCurrentInstance().addMessage(clientId, message);
    }

    public void addCallBack(String name, Object value) {
        PrimeFaces.current().ajax().addCallbackParam(name, value);
    }
}